/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package HandlingInput;

import java.awt.Rectangle;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;

/**
 *
 * @author NGUYEN VAN TAM
 */
public class MouseHanller {
        public static MouseEvent _currentMouse;
        public static MouseEvent _preMouse;

        public static void Update(MouseEvent mouse)
        {
            _preMouse = _currentMouse;
            _currentMouse = mouse;
        }

        public static boolean MouseLeftClick(Rectangle rect)
        {
            if (_currentMouse.getPoint().x >= rect.x && _currentMouse.getPoint().x <= (rect.x + rect.width) &&
                    _currentMouse.getPoint().y >= rect.y && _currentMouse.getPoint().y <= (rect.y + rect.height) && 
                    _currentMouse.getModifiers() == InputEvent.BUTTON1_MASK)
                return true;
            return false;
        }

        public static boolean MouseOver(Rectangle Rect)// Mouse_Over
        {
            if (_currentMouse.getPoint().x >= Rect.x && _currentMouse.getPoint().x <= (Rect.x + Rect.width) &&
                    _currentMouse.getPoint().y >= Rect.y && _currentMouse.getPoint().y <= (Rect.y + Rect.height))
                return true;
            return false;
        }

        public static boolean MouseLeftRelease(Rectangle Rect)
        {
            if (MouseOver(Rect)  && _currentMouse.getID() == MouseEvent.MOUSE_RELEASED)
                return true;
            return false;
        }
}
